package nets

import (
	"bytes"
	"cli/config"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func Flash() {
	targetUrl := config.Config.CliInfo.Url + "/test/flash"
	dataMap := make(map[string]interface{})
	dataMap["sudoAuthentication"] = AuthenticationInfo
	payload, _ := json.Marshal(dataMap)

	req, _ := http.NewRequest("POST", targetUrl, bytes.NewReader(payload))
	response, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	resqData, _ := io.ReadAll(response.Body)
	if response.StatusCode != 200 {
		fmt.Println("Error:", string(resqData))
	} else {
		fmt.Println(string(resqData))
	}
}
func Night() {
	targetUrl := config.Config.CliInfo.Url + "/test/night"
	dataMap := make(map[string]interface{})
	dataMap["sudoAuthentication"] = AuthenticationInfo
	payload, _ := json.Marshal(dataMap)
	req, _ := http.NewRequest("POST", targetUrl, bytes.NewReader(payload))
	response, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	resqData, _ := io.ReadAll(response.Body)
	if response.StatusCode != 200 {
		fmt.Println("Error:", string(resqData))
	} else {
		fmt.Println(string(resqData))
	}
}
func Storage() {
	targetUrl := config.Config.CliInfo.Url + "/test/storage/ram"
	dataMap := make(map[string]interface{})
	dataMap["sudoAuthentication"] = AuthenticationInfo
	payload, _ := json.Marshal(dataMap)

	req, _ := http.NewRequest("POST", targetUrl, bytes.NewReader(payload))
	response, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	resqData, _ := io.ReadAll(response.Body)
	if response.StatusCode != 200 {
		fmt.Println("Error:", string(resqData))
	} else {
		fmt.Println(string(resqData))
	}
}
func GetStorage() {
	targetUrl := config.Config.CliInfo.Url + "/test/get/storage/ram"
	dataMap := make(map[string]interface{})
	dataMap["sudoAuthentication"] = AuthenticationInfo
	payload, _ := json.Marshal(dataMap)

	req, _ := http.NewRequest("POST", targetUrl, bytes.NewReader(payload))
	response, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	resqData, _ := io.ReadAll(response.Body)
	if response.StatusCode != 200 {
		fmt.Println("Error:", string(resqData))
	} else {
		fmt.Println(string(resqData))
	}
}
func Print() {
	targetUrl := config.Config.CliInfo.Url + "/test/print"
	dataMap := make(map[string]interface{})
	dataMap["sudoAuthentication"] = AuthenticationInfo
	payload, _ := json.Marshal(dataMap)

	req, _ := http.NewRequest("POST", targetUrl, bytes.NewReader(payload))
	response, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	resqData, _ := io.ReadAll(response.Body)
	defer response.Body.Close() // 注意要关闭响应体
	if response.StatusCode != 200 {
		fmt.Println("Error:", string(resqData))
	} else {
		fmt.Println(string(resqData))
	}
}
